<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Document</title>
</head>
<body>

  <div id='app'>
    <home></home>
  </div>

<template id="tpl">
  <div>
    <h2>我是HOME页</h2>
    <button >按钮</button>
  </div>
</template>

<script src='https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js'></script>
<script>
  const Child = {
    template: `
      <h5>子组件</h5>
    `
    ,data() {
      return {
        msg: '子组件data'
      }
    }
    ,methods: {
      fn() {
        alert(1)
      }
    }
  }
 
  const Home = {
    template: `
    <div>
      <h3 ref="title">HOME组件</h3>
      <button ref="btn">按钮</button>
      <child ref="child"></child>
    </div>
    `
    ,mounted() {
      // 在这个组件的DOM编译完成后 自动触发
      // console.log(document.querySelector('button'))
      console.log(this.$refs)
      this.$refs.title.style.background="blue"
      console.log(this.$refs.child.msg)
      this.$refs.child.fn()
    }
    ,components: {
      Child
    }
  }
  Vue.component("Home", Home)
  const app = new Vue({
    el: '#app'
  })
</script>
</body>
</html>